#include <stdio.h>
#include <string.h>

#include "thread.h"
#include "device.h"

int at24c02_test(void)
{
    char str[20] = "1234567890abcde";
    char buffer[20];
    mt_device_t *at24cxx;
    
    printf("%s\r\n", __FUNCTION__);
    
    at24cxx = mt_device_open("at24c02", MT_DEVICE_RDWR);
    if(at24cxx == MT_NULL)
        printf("open at24c02 faied\r\n");
    
    if(mt_device_pwrite(at24cxx, str, sizeof(str), 7) != sizeof(str))
        printf("write at24cxx faied\r\n");
    
    memset(buffer, 0, sizeof(buffer));
    if(mt_device_pread(at24cxx, buffer, sizeof(buffer), 7) != sizeof(buffer))
        printf("read at24cxx faied\r\n");
    printf("read:\r\n%s\r\n", buffer);
    
    return 0;
}
